#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int totalFruit(vector<int>& fruits) {
        map<int, int> m;
        int len = 0;
        int i = 0;
        for (int left = 0, right = 0; right < fruits.size(); right++)
        {
            // m.insert(make_pair(fruits[right],1));
            // if(m[0]==fruits[right]||m[1]==fruits[right])
            m[i]++;
            if (m.size() > 2)

                if (flag == 0)
                {
                    ++left;
                    while (fruits[left] == fruits[left - 1])
                        left++;
                    flag++;
                }
            len = max(len, right - left + 1);

        }
        return len;
    }
};